class RangeFreqQuery
{
    unordered_map<int, vector<int>> nums;
public:
    RangeFreqQuery(vector<int>& arr)
    {
        for (int i = 0; i < arr.size(); i++)
        {
            nums[arr[i]].push_back(i);
        }
    }
    int query(int left, int right, int value)
    {
        auto l = lower_bound(nums[value].begin(), nums[value].end(), left);
        auto r = upper_bound(nums[value].begin(), nums[value].end(), right);
        return r - l;
    }
};